clock();
setInterval(clock, 10);
function clock() {
var now = new Date();
var sec = now.getSeconds(),
min = now.getMinutes(),
hour = now.getHours();
hour = hour >= 12 ? hour - 12 : hour;
var k = now % 60000;
var ctx = document.getElementById('myCanvas').getContext('2d');
ctx.save();
ctx.clearRect(0, 0, 300, 300);
ctx.translate(150, 150);
ctx.scale(0.4, 0.4);
ctx.rotate(-Math.PI / 2);
ctx.strokeStyle = '#660';
ctx.fillStyle = '#f0f';
ctx.lineWidth = 8;
ctx.lineCap = 'round';
ctx.save();
ctx.beginPath();
for (var i = 0; i < 12; i++) {
ctx.rotate(Math.PI / 6);
ctx.moveTo(300, 0);
ctx.lineTo(290, 0);
}
ctx.stroke();
ctx.restore();
ctx.save();
ctx.lineWidth = 5;
ctx.beginPath();
for (var i = 0; i < 60; i++) {
if (i % 5 != 0) {
ctx.moveTo(296, 0);
ctx.lineTo(295, 0);
}
ctx.rotate(Math.PI / 30);
}
ctx.stroke();
ctx.restore();
ctx.save();
ctx.rotate(
(Math.PI / 6) * hour + (Math.PI / 360) * min + (Math.PI / 21600) * sec,
);
ctx.lineWidth = 14;
ctx.beginPath();
ctx.moveTo(-10, 0);
ctx.lineTo(175, 0);
ctx.stroke();
ctx.restore();
ctx.save();
ctx.rotate((Math.PI / 30) * min + (Math.PI / 1800) * sec);
ctx.strokeStyle = '#990099';
ctx.lineWith = 10;
ctx.beginPath();
ctx.moveTo(-28, 0);
ctx.lineTo(262, 0);
ctx.stroke();
ctx.restore();
ctx.save();
ctx.rotate((k * Math.PI) / 30000);
ctx.strokeStyle = '#ff0000';
ctx.lineWidth = 1;
ctx.beginPath();
ctx.moveTo(-30, 0);
ctx.lineTo(293, 0);
ctx.stroke();
ctx.restore();
ctx.save();
ctx.lineWidth = 14;
ctx.strokeStyle = '#325FA2';
ctx.beginPath();
ctx.arc(0, 0, 350, 0, Math.PI * 2, true);
ctx.stroke();
ctx.restore();
ctx.restore();
}